package com.wyc.price.controller;

import java.util.List;

import com.wyc.internalCommon.request.PriceRuleDTO;
import com.wyc.internalCommon.result.ApiResult;
import com.wyc.price.service.PriceRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 运价规则Controller
 * 
 * @author li
 * @date 2023-03-23
 */
@RestController
@RequestMapping("/price")
public class PriceRuleController
{
    @Autowired
    private PriceRuleService priceRuleService;

    /**
     * 查询运价规则列表
     */
    @GetMapping("/list")
    public ApiResult list(PriceRuleDTO priceRuleDTO)
    {
        List<PriceRuleDTO> list = priceRuleService.selectPriceRuleList(priceRuleDTO);
        return ApiResult.success(list);
    }

    /**
     * 查询计价规则是否是最新版本
     * @param priceRuleDTO
     * @return
     */
    @PostMapping("/isNew")
    public ApiResult isNew(@RequestBody PriceRuleDTO priceRuleDTO){
        return ApiResult.success(priceRuleService.isNew(priceRuleDTO));
    }

    /**
     * 新增运价规则
     */
    @PostMapping("/add")
    public ApiResult add(@RequestBody PriceRuleDTO priceRuleDTO)
    {
        return priceRuleService.insertPriceRule(priceRuleDTO);
    }

    /**
     * 修改运价规则
     */
    @PutMapping("/update")
    public ApiResult edit(@RequestBody PriceRuleDTO priceRuleDTO)
    {
        return priceRuleService.updatePriceRule(priceRuleDTO);
    }

    /**
     * 判断该城市和对应车型的计价规则是否存在
     * @param priceRuleDTO
     * @return
     */
    @PostMapping("/if-exists")
    public ApiResult ifExists(@RequestBody PriceRuleDTO priceRuleDTO){
        return priceRuleService.ifExists(priceRuleDTO);
    }

}
